#!/usr/bin/env python3
"""
高德地图路径规划工具使用示例
"""

import os
import sys
from dotenv import load_dotenv

# 添加项目根目录到Python路径
from pathlib import Path
project_root = Path(__file__).parent.parent.parent
sys.path.insert(0, str(project_root))

from src.tools.amap_navigation import AmapNavigationTool

def main():
    """主函数"""
    # 加载环境变量
    load_dotenv()
    
    try:
        # 初始化工具
        print("正在初始化高德地图路径规划工具...")
        nav_tool = AmapNavigationTool()
        print("工具初始化成功！")
        
        # 示例：规划从成都天府广场到成都火车站的路线
        origin = "成都天府广场"
        destination = "成都火车站"
        city = "成都"
        
        print(f"\n正在规划路线: {origin} -> {destination}")
        print("=" * 50)
        
        # 获取所有出行模式的摘要
        print("获取路线摘要...")
        summary = nav_tool.get_route_summary(origin, destination, city)
        
        for mode, info in summary.items():
            mode_names = {
                "walking": "步行",
                "cycling": "骑行", 
                "driving": "驾车",
                "transit": "公共交通"
            }
            
            print(f"\n{mode_names.get(mode, mode)}模式:")
            if "error" in info:
                print(f"  规划失败: {info['error']}")
            else:
                print(f"  距离: {info['distance']}")
                print(f"  耗时: {info['duration']}")
                if info.get('cost'):
                    print(f"  费用: {info['cost']}")
                if info.get('tolls'):
                    print(f"  过路费: {info['tolls']}")
        
        # 详细规划步行路线
        print(f"\n详细步行路线规划:")
        print("=" * 50)
        try:
            walking_route = nav_tool.plan_walking_route(origin, destination, city)
            formatted_route = nav_tool.format_route_info(walking_route)
            print(formatted_route)
        except Exception as e:
            print(f"步行路线规划失败: {e}")
        
        # 详细规划公共交通路线
        print(f"\n详细公共交通路线规划:")
        print("=" * 50)
        try:
            transit_route = nav_tool.plan_transit_route(origin, destination, city)
            formatted_route = nav_tool.format_route_info(transit_route)
            print(formatted_route)
        except Exception as e:
            print(f"公共交通路线规划失败: {e}")
            
    except Exception as e:
        print(f"程序执行失败: {e}")
        print("\n请确保:")
        print("1. 已在.env文件中配置了AMAP_API_KEY")
        print("2. 网络连接正常")
        print("3. 高德地图API密钥有效")

if __name__ == "__main__":
    main()
